package com.guigu.qingcheng.controller;

import com.guigu.qingcheng.service.UserFeign;
import com.qingcheng.entity.Result;
import com.qingcheng.pojo.user.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

@Controller
public class RegisterController {

    @Autowired
    private UserFeign userFeign;

    //跳转注册页面
    @RequestMapping("/registerUI")
    public String registerUI(){
        return "register";
    }

    //发送验证码
    @GetMapping("/sendSms")
    @ResponseBody
    public Result sendMsg(String phone){
        Result result = userFeign.sendMsg(phone);
        if(result.getCode() != 200){
            throw new RuntimeException("注册失败");
        }
        return result;
    }

    @PostMapping("/register")
    public Result register(@RequestBody User user, String smsCode){
        Result save = userFeign.save(user, smsCode);
        if(save.getCode() != 200){
            throw new RuntimeException("注册失败");
        }
        return save;
    }
}
